package GraphTheory;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

class Pair
{	public int x,y;
	public Pair(int X,int Y)
	{	x=X;y=Y;
	}
}
class SpanningTree
{	public int root;
	public Queue<Pair> Rem;
	public SpanningTree(int r)
	{	root=r;Rem=new LinkedList<Pair>();
	}
}
class Solver1709
{	int n,d,a;
	long nd,na,rs;
	int[][] Map,Rs;
	boolean[] Visited;
	
	public void Input()
	{	Scanner in=new Scanner(System.in);
		n=in.nextInt();
		d=in.nextInt();
		a=in.nextInt();
		
		Visited=new boolean[n+1];Arrays.fill(Visited,false);
		Map=new int[n+1][n+1];Rs=new int[n+1][n+1];
		in.nextLine();
		for (int i=1;i<=n;i++)
		{	String str=in.nextLine();
			for (int j=0;j<str.length();j++)
				Map[i][j+1]=(str.charAt(j)-'0');
		}
		for (int i=0;i<Rs.length;i++)
			Arrays.fill(Rs[i],0);
		nd=0;na=0;
	}
	private SpanningTree SpanningTree(int f)
	{	Visited[f]=true;
		SpanningTree spt=new SpanningTree(f);
		Queue<Integer> lst=new LinkedList<Integer>();
		lst.add(f);
		while (!lst.isEmpty())
		{	f=lst.remove();
			for (int i=1;i<=n;i++)
				if (Map[f][i]==1)
				{	if (!Visited[i])
					{	Visited[i]=true;
						lst.add(i);
						Map[f][i]=3;Map[i][f]=3;
					}
					else if (f<i)
					{	spt.Rem.add(new Pair(f,i));
						nd++;
					}
				}		
		}
		return spt;
	}
	public void Solve()
	{	Queue<SpanningTree> Global=new LinkedList<SpanningTree>();
		for (int i=1;i<=n;i++)
			if (!Visited[i]) Global.add(SpanningTree(i));
		na=Global.size()-1;
		rs=nd*d+na*a;
		int old=-1;
		while (!Global.isEmpty())
		{	SpanningTree spt=Global.remove();
			if (old!=-1)
			{	Rs[old][spt.root]=2;
				Rs[spt.root][old]=2;
			}
			while (!spt.Rem.isEmpty())
			{	Pair p=spt.Rem.remove();
				Rs[p.x][p.y]=1;Rs[p.y][p.x]=1;
			}
			old=spt.root;
		}
	}
	public void Output()
	{	System.out.println(rs);
		for (int i=1;i<=n;i++)
		{	for (int j=1;j<=n;j++)
				switch (Rs[i][j])
				{	case 0:	System.out.print(0);break;
					case 1:	System.out.print('d');break;
					case 2:	System.out.print('a');break;
				}
			System.out.println();
		}
	}
	public void main()
	{	Input();
		Solve();
		Output();
	}
}
public class P1709
{	public static void main(String[] args)
	{	Solver1709 solver=new Solver1709();
		solver.main();
	}
}
